<!-- 添加开票信息 -->

<template>
  <el-drawer
    v-model="drawerVisible"
    :close-on-click-modal="false"
    :destroy-on-close="true"
    size="1000px"
    :title="drawerProps.title"
  >
    <el-form
      ref="ruleFormRef"
      label-position="top"
      require-asterisk-position="right"
      :inline="true"
      :rules="rules"
      :model="params"
      class="form-inline-wrap"
    >
      <el-form-item label="发票类型" prop="invoiceType">
        <el-radio-group v-model="params.invoiceType">
          <el-radio value="1" size="large">普通发票</el-radio>
          <el-radio value="2" size="large">专用发票</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="抬头类型" prop="headUpType">
        <el-radio-group v-model="params.headUpType">
          <el-radio value="1" size="large">企业单位</el-radio>
          <el-radio value="2" size="large">个人/非企业单位</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="公司名称" prop="companyName">
        <el-input v-model="params.companyName" placeholder="请输入公司名称"></el-input>
      </el-form-item>
      <el-form-item label="公司税号" prop="companyTaxNumber">
        <el-input v-model="params.companyTaxNumber" placeholder="请输入公司税号"></el-input>
      </el-form-item>
      <el-form-item label="注册电话">
        <el-input v-model="params.registeredPhone" placeholder="请输入注册电话"></el-input>
      </el-form-item>
      <el-form-item label="注册地址">
        <el-input v-model="params.registeredAddress" placeholder="请输入注册地址"></el-input>
      </el-form-item>
      <el-form-item label="银行账户">
        <el-input v-model="params.bankAccount" placeholder="请输入银行账户"></el-input>
      </el-form-item>
      <el-form-item label="开户银行">
        <el-input v-model="params.depositaryBank" placeholder="请输入开户银行"></el-input>
      </el-form-item>
      <el-form-item label="默认抬头">
        <el-switch
          v-model="params.defaultHeadUp"
          inline-prompt
          active-text="是"
          inactive-text="否"
          :active-value="1"
          :inactive-value="0"
        />
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button @click="close">取消</el-button>
      <el-button type="primary" @click="handleSubmit">确定</el-button>
    </template>
  </el-drawer>
</template>

<script setup lang="ts">
import { ref, reactive, defineEmits } from "vue";

const rules = reactive({
  invoiceType: [{ required: true, message: "请选择发票类型" }],
  headUpType: [{ required: true, message: "请选择抬头类型" }],
  companyName: [{ required: true, message: "请输入公司名称" }],
  companyTaxNumber: [{ required: true, message: "请输入公司税号" }]
});

interface DrawerProps {
  title: string;
  id: number;
  getTableList?: () => void;
}

const drawerVisible = ref(false);
const drawerProps = ref<DrawerProps>({
  title: "",
  id: 0
});
const params = ref({
  invoiceType: "1",
  headUpType: "1",
  defaultHeadUp: 1
});

// 接收父组件传过来的参数
const acceptParams = (params: DrawerProps) => {
  drawerProps.value = params;
  drawerVisible.value = true;
};

// 提交数据（新增/编辑）
const ruleFormRef = ref();
const handleSubmit = () => {
  ruleFormRef.value!.validate(async valid => {
    if (!valid) return;
    try {
      //   await drawerProps.value.api!(drawerProps.value.row);
      //   ElMessage.success({ message: `${drawerProps.value.title}用户成功！` });
      //   drawerProps.value.search!();
      //   drawerVisible.value = false;
    } catch (error) {
      console.log(error);
    }
  });
};

const emit = defineEmits(["close"]);
const close = () => {
  drawerVisible.value = false;
  emit("close");
};

defineExpose({
  acceptParams
});
</script>
